﻿using FirstFloor.ModernUI.Windows.Controls;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MetroGS.AppClass
{
    class UpdateAndInstall
    {
        public void lookforupdate(MainWindow Window)
        {
            string remoteUri = "https://dl.dropboxusercontent.com/s/op4w2ie63r5mgxp/metrogs_version.txt?token_hash=AAEdqPVme2QhUW_U1ZrYQOHefR0IKt9KVAfI0d1PTAGhug&dl=1";
            string fileName = "metrogs_version.txt", myStringWebResource = null;

            WebClient myWebClient = new WebClient();
            using (myWebClient)
            {
                myStringWebResource = remoteUri + fileName;
                myWebClient.DownloadFile(myStringWebResource, fileName);
            }

            String rversion;
            using (StreamReader sr = new StreamReader("metrogs_version.txt"))
            {
                rversion = sr.ReadToEnd();
            }

            string cversion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

            if (cversion != rversion)
            {
                var result = ModernDialog.ShowMessage("Do you want to download it now?", "Update available", MessageBoxButton.OKCancel);
                if (result == true)
                {
                    System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    proc.EnableRaisingEvents = false;

                    proc.StartInfo.FileName = "https://www.dropbox.com/sh/fzi5l1esfvmt912/DAjZ2SJ2lX";
                    proc.Start();
                }
            }
        }
    }
}
